//
//  MovieDetailView.m
//  豆瓣(阿黄)
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailView.h"
#import "UIImageView+WebCache.h"

@implementation MovieDetailView

-(instancetype)initWithFrame:(CGRect)frame{

    [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView{

    self.poster = [[UIImageView alloc] initWithFrame:CGRectMake(25, 15, 110, 180)];
//    self.poster.backgroundColor = [UIColor grayColor];
    [self addSubview:self.poster];
    [self.poster release];
    
    self.rating = [[UILabel alloc] initWithFrame:CGRectMake(155, 25, 100, 25)];
//    self.rating.backgroundColor = [UIColor grayColor];
    [self addSubview:self.rating];
    [self.rating release];
    
    self.rating_count = [[UILabel alloc] initWithFrame:CGRectMake(240, 25, 80, 25)];
//    self.rating_count.backgroundColor = [UIColor grayColor];
    [self addSubview:self.rating_count];
    [self.rating_count release];
    
    self.release_date = [[UILabel alloc] initWithFrame:CGRectMake(155, 60, 200, 25)];
//    self.release_date.backgroundColor = [UIColor grayColor];
    [self addSubview:self.release_date];
    [self.release_date release];
    
    self.runtime = [[UILabel alloc] initWithFrame:CGRectMake(155, 95, 150, 25)];
//    self.runtime.backgroundColor = [UIColor grayColor];
    [self addSubview:self.runtime];
    [self.runtime release];
    
    self.genres = [[UILabel alloc] initWithFrame:CGRectMake(155, 130, 200, 25)];
//    self.genres.backgroundColor = [UIColor grayColor];
    [self addSubview:self.genres];
    [self.genres release];
    
    self.country = [[UILabel alloc] initWithFrame:CGRectMake(155, 165, 150, 25)];
//    self.country.backgroundColor = [UIColor grayColor];
    [self addSubview:self.country];
    [self.country release];
    
    self.actorsLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 205, 150, 40)];
    self.actorsLabel.text = @"制作人";
    self.actorsLabel.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:self.actorsLabel];
    [self.actorsLabel release];
    
    self.actors = [[UILabel alloc] initWithFrame:CGRectMake(25, 245, 300, 70)];
//    self.actors.backgroundColor = [UIColor grayColor];
    self.actors.numberOfLines = 0;
    [self addSubview:self.actors];
    [self.actors release];
    
    self.plot_simpleLable = [[UILabel alloc] initWithFrame:CGRectMake(35, 315, 150, 40)];
    self.plot_simpleLable.text = @"电影情节";
    self.plot_simpleLable.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:self.plot_simpleLable];
    [self.plot_simpleLable release];
    
    self.plot_simple = [[UILabel alloc] initWithFrame:CGRectMake(25, 365, 300, 300)];
//    self.plot_simple.backgroundColor = [UIColor grayColor];
    self.plot_simple.numberOfLines = 0;
    [self addSubview:self.plot_simple];
    [self.plot_simple release];

}

-(void)setMovieD:(MovieDetail *)movieD{

    if (_movieD != movieD) {
        [_movieD release];
        _movieD = [movieD retain];
    }
    
    self.plot_simple.text = self.movieD.plot_simple;
    self.title.text = self.movieD.title;
//    NSLog(@"%@",self.movieD.title);
    self.genres.text = self.movieD.genres;
    self.country.text = self.movieD.country;
    self.runtime.text = self.movieD.runtime;
    self.rating.text = [NSString stringWithFormat:@"评分:   %@",self.movieD.rating];
    self.rating_count.text = [NSString stringWithFormat:@"(%@评论)",self.movieD.rating_count];
    self.release_date.text = self.movieD.release_date;
    self.actors.text = self.movieD.actors;
    
    NSURL *url = [NSURL URLWithString:self.movieD.poster];
    [self.poster sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
    
    
//    CGFloat height = [MovieDetailView heightForContent:self.plot_simple.text];
//    NSLog(@"%@", self.plot_simple.text);
//    CGRect tempFrame = self.plot_simple.frame;
//    tempFrame.size.height = height;
//    self.plot_simple.frame = tempFrame;

}

#pragma mark -- 计算内容高度第一步:封装算法
+ (CGFloat)heightForContent:(NSString *)content{
    
    //参数1.设置计算高度按照什么样的size来计算
    //宽度一定与lable宽度一致,高度尽量大些
    //参数2.设置计算类型
    //参数3.设置计算内容按照多大的字体计算
    //注意:字体大小也要跟label字体一样
    //参数4.系统备用参数,设置为nil
    CGSize size = CGSizeMake(300, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         [UIFont systemFontOfSize:17.0], NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}


@end
